package com.teach.controller;

import com.teach.entity.ResponseEntity;
import com.teach.entity.TbPower;
import com.teach.service.TbPowerService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/power")
public class PowerController {
    @Resource
    private TbPowerService tbPowerService;

    @RequestMapping("/list")
    public ResponseEntity getAll(){
        return tbPowerService.getAll();
    }

    @RequestMapping("/powerSave")
    public ResponseEntity powerSave(@RequestBody TbPower tbPower, HttpServletRequest request){
        String token = request.getHeader("token");
        return tbPowerService.powerSave(tbPower,token);
    }

    @RequestMapping("/findById")
    public ResponseEntity findById(@RequestParam(value = "id")Integer id){
        return tbPowerService.findById(id);
    }

    @RequestMapping("/updatePower")
    public ResponseEntity updatePower(@RequestBody TbPower tbPower,HttpServletRequest request){
        String token = request.getHeader("token");
        return tbPowerService.updatePower(tbPower,token);
    }
}
